package cn.dy.sbo.web.sys;

import java.util.List;

import cn.common.lib.springside.web.CrudActionSupport;
import cn.dy.sbo.core.PartnerManager;
import cn.dy.sbo.core.UserManager;
import cn.dy.sbo.model.Partner;
import cn.dy.sbo.model.User;
import cn.dy.sbo.vo.UserVO;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import org.springside.modules.utils.web.struts2.Struts2Utils;

@Namespace("/sys")
@Results( { @Result(name = CrudActionSupport.RELOAD, location = "user.action", type = "redirect") })
public class CustomerAction extends ActionSupport implements Preparable
{
    private static final long serialVersionUID = 8683878162525847072L;

    // -- 页面属性 --//

    private Long              id;                                     // 全局Id

    private Page<Partner>        page             = new Page<Partner>(10);  // 每页10条记录

    @Autowired
    private PartnerManager       partnerManager;

    private Partner partner;
    
    @Override
    public String execute() throws Exception
    {
        List<PropertyFilter> filters = PropertyFilter
        .buildFromHttpRequest(Struts2Utils.getRequest());
        page = partnerManager.search(page, filters);
        return SUCCESS;
    }

    /**
     * 删除用户
     *
     */
    public String delete() throws Exception
    {
        return "reload";
    }

   
    /**
     * 进入保存用户页面
     * 
     * @since 2011-11-10
     * @see cn.common.lib.springside.web.CrudActionSupport#input()
     */
    @Override
    public String input() throws Exception
    {
        return INPUT;
    }

    

    /**
     * 保存用户信息
     * 
     * @since 2011-11-8
     * @see cn.common.lib.springside.web.CrudActionSupport#save()
     */
    public String save()
    {
    	partnerManager.save(partner);
        return "reload";
    }

    

    public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	
	protected void prepareSave() throws Exception
    {
        if (null != id)
        {
        	partner = partnerManager.get(id);
        }
        else
        {
        	partner = new Partner();
        }
    }
	
	

	public Page<Partner> getPage() {
		return page;
	}

	public void setPage(Page<Partner> page) {
		this.page = page;
	}

	public Partner getPartner() {
		return partner;
	}

	public void setPartner(Partner partner) {
		this.partner = partner;
	}

	@Override
	public void prepare() throws Exception {
		
	}
}